﻿using Newtonsoft.Json;
using System;

namespace CMS.Infos
{
    public class Assistant : ICloneable, IAssignable
    {
        [JsonProperty(PropertyName = "id")]
        public int ID { get; set; }

        [JsonProperty(PropertyName = "name")]
        public string Name { get; set; }

        [JsonProperty(PropertyName = "class_name")]
        public string ClassName { get; set; }

        [JsonProperty(PropertyName = "phone")]
        public string Phone { get; set; }

        [JsonProperty(PropertyName = "credit_id")]
        public string CreditID { get; set; }

        [JsonProperty(PropertyName = "college")]
        public string College { get; set; }

        public override int GetHashCode()
        {
            return ID ^ (Name?.GetHashCode() ?? 0) ^ (ClassName?.GetHashCode() ?? 0) ^ (Phone?.GetHashCode() ?? 0) ^ (CreditID?.GetHashCode() ?? 0);
        }

        public override bool Equals(object obj)
        {
            if (obj is Assistant assistant)
            {
                return assistant.ID == ID && assistant.Name == Name && assistant.Phone == Phone && assistant.ClassName == ClassName && assistant.CreditID == CreditID&&assistant.College==College;
            }
            else
            {
                return false;
            }
        }
        public override string ToString()
        {
            return Name;
        }

        public object Clone()
        {
            return new Assistant().Assign(this);
        }

        public object Assign(object src)
        {
            if (src is Assistant src2)
            {
                Name = src2.Name;
                ID = src2.ID;
                ClassName = src2.ClassName;
                Phone = src2.Phone;
                CreditID = src2.CreditID;
                College = src2.College;
            } else
            {
                throw new ArgumentException();
            }
            return this;
        }
    }
}
